#!/bin/sh

# Copyright (C) 2015  Ville Pätsi <drc@gimp.org>

SCRIPT_FOLDER=$( cd "$( dirname "$0")" && pwd )

FIRST_COMMIT="$1"
[ -z "$FIRST_COMMIT" ] && FIRST_COMMIT="950412fbdc720fe2600f58f04f25145d9073895d" # First after tag 2.8.0

FOLDERS="app;tools;menus;etc \
    libgimp;libgimpbase;libgimpcolor;libgimpconfig;libgimpmath;libgimpmodule;libgimpthumb;libgimpwidgets \
    plug-ins \
    modules \
    build \
    themes"

OUTPUTFILE=${SCRIPT_FOLDER}/../NEWS_since_"${FIRST_COMMIT}"

old_dir=$(pwd)
cd ${SCRIPT_FOLDER}/..

for folderloop in $FOLDERS; do
    folderloop=$(echo "$folderloop" | sed "s/;/ /g")
    uppercase_folderloop="`echo ${folderloop} | cut -c1 | tr '[:lower:]' '[:upper:]'``echo ${folderloop} | cut -c2-`"
    printf "\n${uppercase_folderloop}:\n\n" >> "${OUTPUTFILE}"
    for folder in $folderloop; do
        git log --date-order --reverse --date=short --pretty=format:"- %h %s" "${FIRST_COMMIT}"..HEAD ${folder} >> "${OUTPUTFILE}"
    done
    printf "\n\n" >> "${OUTPUTFILE}"
done

cd $old_dir

echo "NEWS generated into ${OUTPUTFILE}"
